package socket;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

import Static.StaticTest;

public class MyClient {
	static Socket server;

	public static void main(String[] args) throws Exception {
		System.out.println(InetAddress.getByName("10.9.50.197"));
		server = new Socket(InetAddress.getLocalHost(), 5679);
		server.setSoTimeout(0);
		BufferedReader in = new BufferedReader(new InputStreamReader(server.getInputStream()));
		PrintWriter out = new PrintWriter(server.getOutputStream());
		BufferedReader wt = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String str = wt.readLine();
			out.println("client:" + str);
			out.flush();
			if (str.equals("end")) {
				break;
			}
			byte[] b = new byte[10];
			int len = 0;
			//InputStream is = server.getInputStream();
			//DataInputStream dataInputStream = new DataInputStream(is);
			char[] ch = new char[1024];
			int count = 0;
			char temp;
			int i = 0;
			//while(!"".equals(in.readLine())){
			System.out.println(in.readLine());
			System.out.println("i:" + i++);
			//}
			//			while ((temp = dataInputStream.readChar()) != 'C') {
			//				ch[count++] = temp;
			//				if(count == 5)
			//					server.shutdownOutput();
			//			}
			//			System.out.println(ch);
			//			while((len = is.read(b))!=-1){
			//				System.out.println("len:"+len);
			//				System.out.println(new String(b));
			//			}
			//is.read(b);
			//System.out.println(new String(b));
			//			System.out.println("clientsys:");
			//			System.out.println("clientsys:" + in.readLine());
			//System.out.println("static:" + StaticTest.a);
		}
		server.close();
	}

	public static void sockets() throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(server.getInputStream()));
		PrintWriter out = new PrintWriter(server.getOutputStream());
		BufferedReader wt = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String str = wt.readLine();
			out.println("client:" + str);
			out.flush();
			if (str.equals("end")) {
				break;
			}
			System.out.println("clientsys:");
			System.out.println("clientsys:" + in.readLine());
			System.out.println("static:" + StaticTest.a);
		}
		server.close();
	}
}
